package com.school.graduation.classification.presenter;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.school.graduation.R;
import com.school.graduation.classification.adapter.ViewPagerAdapter;
import com.school.graduation.classification.model.ClassIficationModel;
import com.school.graduation.classification.view.ImplClassIfication;
import com.school.graduation.goods.view.FoundGoodDetailsActivityNew;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ClassIficationPresenter implements View.OnClickListener{
    private ImplClassIfication view;
    private ClassIficationModel model;
    private Context context;
    private LayoutInflater inflater;
    private List<View> viewsList1;
    private List<View> viewsList2;
    private LinearLayout item1;
    private LinearLayout item2;
    private LinearLayout item3;
    private LinearLayout item4;
    private LinearLayout item5;
    private LinearLayout item6;
    private LinearLayout item7;
    private LinearLayout item8;
    private LinearLayout item9;
    private LinearLayout item10;
    private LinearLayout item11;
    private LinearLayout item12;
    private LinearLayout item13;
    private LinearLayout item14;
    private LinearLayout item15;
    private LinearLayout item16;
    private LinearLayout appliancesitem1;
    private LinearLayout appliancesitem2;
    private LinearLayout appliancesitem3;
    private LinearLayout appliancesitem4;
    private LinearLayout appliancesitem5;
    private LinearLayout appliancesitem6;

    private HashMap<Integer,String> types;
    public ClassIficationPresenter(Context context, ImplClassIfication view, LayoutInflater inflater){
        this.context = context;
        this.view = view;
        this.inflater = inflater;
        model = new ClassIficationModel(context,this);
    }

    //设置两个ViewPager
    public void setViewPager(){
        iniTypes();
        viewsList1 = new ArrayList<View>();
        viewsList2 = new ArrayList<View>();
        View view1 = inflater.inflate(R.layout.view_classification_one,null);
        View view2 = inflater.inflate(R.layout.view_classification_two,null);
        View view3 = inflater.inflate(R.layout.view_electricappliance_one,null);
        View view4 = inflater.inflate(R.layout.view_electricappliance_two,null);
        item1 = (LinearLayout)view1.findViewById(R.id.view_classification_1);
        item2 = (LinearLayout)view1.findViewById(R.id.view_classification_2);
        item3 = (LinearLayout)view1.findViewById(R.id.view_classification_3);
        item4 = (LinearLayout)view1.findViewById(R.id.view_classification_4);
        item5 = (LinearLayout)view1.findViewById(R.id.view_classification_5);
        item6 = (LinearLayout)view1.findViewById(R.id.view_classification_6);
        item7 = (LinearLayout)view1.findViewById(R.id.view_classification_7);
        item8 = (LinearLayout)view1.findViewById(R.id.view_classification_8);
        item9 = (LinearLayout)view2.findViewById(R.id.view_classification_9);
        item10 = (LinearLayout)view2.findViewById(R.id.view_classification_10);
        item11 = (LinearLayout)view2.findViewById(R.id.view_classification_11);
        item12 = (LinearLayout)view2.findViewById(R.id.view_classification_12);
        item13 = (LinearLayout)view2.findViewById(R.id.view_classification_13);
        item14 = (LinearLayout)view2.findViewById(R.id.view_classification_14);
        item15 = (LinearLayout)view2.findViewById(R.id.view_classification_15);
        item16 = (LinearLayout)view2.findViewById(R.id.view_classification_16);
        appliancesitem1 = (LinearLayout)view3.findViewById(R.id.view_classification_appliances_1);
        appliancesitem2 = (LinearLayout)view3.findViewById(R.id.view_classification_appliances_2);
        appliancesitem3 = (LinearLayout)view3.findViewById(R.id.view_classification_appliances_3);
        appliancesitem4 = (LinearLayout)view4.findViewById(R.id.view_classification_appliances_4);
        appliancesitem5 = (LinearLayout)view4.findViewById(R.id.view_classification_appliances_5);
        appliancesitem6 = (LinearLayout)view4.findViewById(R.id.view_classification_appliances_6);
        setClickListener();
        viewsList1.add(view1);
        viewsList1.add(view2);
        viewsList2.add(view3);
        viewsList2.add(view4);
        ViewPagerAdapter adapter1 = new ViewPagerAdapter(context,viewsList1);
        ViewPagerAdapter adapter2 = new ViewPagerAdapter(context,viewsList2);
        view.setViewPager(adapter1,adapter2);
    }

    private void iniTypes(){
        types = new HashMap<Integer, String>();
        types.put(R.id.view_classification_appliances_1, "游戏机");
        types.put(R.id.view_classification_appliances_2, "kindle");
        types.put(R.id.view_classification_appliances_3, "移动电源");
        types.put(R.id.view_classification_appliances_4, "摄影发烧");
        types.put(R.id.view_classification_appliances_5, "mp4");
        types.put(R.id.view_classification_appliances_6, "耳机");
        types.put(R.id.view_classification_1,"手机");
        types.put(R.id.view_classification_2,"电脑");
        types.put(R.id.view_classification_3,"家用电器");
        types.put(R.id.view_classification_4,"服装鞋帽");
        types.put(R.id.view_classification_5,"个性化妆");
        types.put(R.id.view_classification_6,"运动户外");
        types.put(R.id.view_classification_7,"交通工具");
        types.put(R.id.view_classification_8,"珠宝配饰");
        types.put(R.id.view_classification_9,"玩具乐器");
        types.put(R.id.view_classification_10,"艺术古玩");
        types.put(R.id.view_classification_11,"技能服务");
        types.put(R.id.view_classification_12,"票务卡券");
        types.put(R.id.view_classification_13,"动漫周边");
        types.put(R.id.view_classification_14,"图书音像");
        types.put(R.id.view_classification_15,"家居家纺");
        types.put(R.id.view_classification_16,"工具建材");
    }

    private void setClickListener(){
        item1.setOnClickListener(this);
        item2.setOnClickListener(this);
        item3.setOnClickListener(this);
        item4.setOnClickListener(this);
        item5.setOnClickListener(this);
        item6.setOnClickListener(this);
        item7.setOnClickListener(this);
        item8.setOnClickListener(this);
        item9.setOnClickListener(this);
        item10.setOnClickListener(this);
        item11.setOnClickListener(this);
        item12.setOnClickListener(this);
        item13.setOnClickListener(this);
        item14.setOnClickListener(this);
        item15.setOnClickListener(this);
        item16.setOnClickListener(this);
        appliancesitem1.setOnClickListener(this);
        appliancesitem2.setOnClickListener(this);
        appliancesitem3.setOnClickListener(this);
        appliancesitem4.setOnClickListener(this);
        appliancesitem5.setOnClickListener(this);
        appliancesitem6.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        Bundle bundle = new Bundle();
        String item = types.get(v.getId());
        bundle.putString("item",item);
        switch (v.getId()){
            case R.id.view_classification_appliances_1:
                bundle.putBoolean("hot",false);
                break;
            case R.id.view_classification_appliances_2:
                bundle.putBoolean("hot",false);
                break;
            case R.id.view_classification_appliances_3:
                bundle.putBoolean("hot",false);
                break;
            case R.id.view_classification_appliances_4:
                bundle.putBoolean("hot",false);
                break;
            case R.id.view_classification_appliances_5:
                bundle.putBoolean("hot",false);
                break;
            case R.id.view_classification_appliances_6:
                bundle.putBoolean("hot",false);
                break;
            default:
                bundle.putBoolean("hot",true);
                break;
        }
        /*item = types.get(v.getId());
        bundle = new Bundle();
        bundle.putBoolean("hot",true);
        bundle.putString("item",item);*/
        FoundGoodDetailsActivityNew.toDetail(context,bundle);
    }
}
